/*
 * @Author: szx
 * @Date: 2021-10-30 11:47:09
 * @LastEditTime: 2021-10-30 12:02:03
 * @Description:
 * @FilePath: \leetcode\500-599\566\566.cpp
 */
#include <iostream>
#include <vector>
using namespace std;
class Solution {
   public:
    vector<vector<int>> matrixReshape(vector<vector<int>>& mat, int r, int c) {
        int n = mat.size();
        int m = mat[0].size();
        if (n * m != r * c) {
            return mat;
        }
        vector<vector<int>> v;
        for (int i = 0; i < r; i++) {
            v.push_back({});
            for (int j = 0; j < c; j++) {
                int x = i * c + j;
                v[i].push_back(mat[x / m][x % m]);
            }
        }
        return v;
    }
};
int main() {
    Solution s;

    return 0;
}